Re: [GENERAL] Any ideas why this doesn't work or how to rewrite it? - Mailing list pgsql-general

From Herouth Maoz
Subject Re: [GENERAL] Any ideas why this doesn't work or how to rewrite it?
Date
Msg-id l03130307b34e1da86145@[147.233.159.109]
Whole thread Raw
In response to Any ideas why this doesn't work or how to rewrite it?  (Aaron Holtz <aholtz@bright.net>)
Responses Re: [GENERAL] Any ideas why this doesn't work or how to rewrite it?  ("Brett W. McCoy" <bmccoy@lan2wan.com>)
List pgsql-general
At 18:50 +0300 on 28/04/1999, Aaron Holtz wrote:


> db=> select count(distinct customer_username) from customerdata;
> ERROR:  parser: parse error at or near "distinct"
>
> How do you get a count of distinct data output via postgres?  I can always
> just count the number of tuples returned but this seemed to be a valid
> query.

Valid it is, but not yet supported in PostgreSQL.

An (ugly) workaround would be something along the lines of:

SELECT count(customer_username)
FROM customerdata c1
WHERE int( oid ) = (
  SELECT min( int( c2.oid ) )
  FROM customerdata c2
  WHERE c1.customer_username = c2.customer_username
);

The WHERE clause causes only rows whose OIDs are the minimal for the
current username to be selected. Thus only one row is selected for each
username. And this is countable.

Herouth

--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma



pgsql-general by date:

Previous
From: Margarita Barvinok
Date:
Subject: Re: [GENERAL] LIMIT QUESTION
Next
From: "Jun Zhang"
Date:
Subject: Re: [GENERAL] UnixWare chokes --- Resolution